/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.surveilans.model;

import com.surveilans.classes.User;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Yudi Retanto
 */
public class UserModel extends Model {

    public UserModel() {
        super();
    }

    public int validate(String username, String password) {
        int userId = 0;
        Statement stmt = null;

        try {
            stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM user WHERE username='"+username +"' AND password=MD5('"+password+"')");

            while (rs.next()) {
                userId = rs.getInt("id");
            }
        } catch (SQLException ex) {
            Logger.getLogger(UserModel.class.getName()).log(Level.SEVERE, null, ex);
        }

        return userId;
    }
}

